import { BaseEntity } from "./BaseEntity";
import {Column, Entity, JoinTable, OneToMany, OneToOne, PrimaryGeneratedColumn} from "typeorm";
import {ApiProperty} from "@nestjs/swagger";
import {DefaultEnum} from "../common/enum/DefaultEnum";
import {GoodsPrice} from "./GoodsPrice";
import { Stock } from "./Stock";

@Entity()
export class Unit extends BaseEntity {

    constructor(unitId?: number, unit?: string, count?: number, isDefault?: number) {
        super();
        this.unitId = unitId;
        this.unit = unit;
        this.count = count;
        this.isDefault = isDefault;
    }

    @ApiProperty({description: "主键ID"})
    @PrimaryGeneratedColumn({comment: "主键ID", name:"unit_id"})
    unitId: number;

    @ApiProperty({description: "单位名称"})
    @Column({comment: "单位名称"})
    unit: string;

    @ApiProperty({description: "数量"})
    @Column({comment: "数量"})
    count: number;

    @ApiProperty({description: '是否默认（默认标识不可删除，仅管理员可操作）：0-否；1-是', example: 0})
    @Column({name:'is_default', comment: '是否默认（默认标识不可删除，仅管理员可操作）：0-否；1-是', default: 0})
    isDefault: number;

    /**
     * 关联关系
     */
    @OneToMany(type => GoodsPrice, price => price.unit, {createForeignKeyConstraints: false})
    goodsPrice: GoodsPrice;
}
